package com.example.learn.hwod;

import java.util.*;

public class _26单词接龙 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int index = sc.nextInt();
        int n = sc.nextInt();

        //以字母x开头的单词集合
        HashMap<Character,ArrayList<String> > map = new HashMap<>();
        ArrayList<String> words = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String word = sc.next();
            words.add(word);
            char c = word.charAt(0);
            ArrayList<String> strings = map.get(c);
            if (strings == null) {
                strings = new ArrayList<>();
                strings.add(word);
                map.put(c,strings);
            }else{
                strings.add(word);
            }
            strings.sort(Comparator.comparingInt(String::length).reversed().thenComparing(Comparator.naturalOrder()));



        }
        String word = words.get(index);
        char c = word.charAt(0);
        ArrayList<String> strings = map.get(c);
        for (int i = 0; i < strings.size(); i++) {
            if (word.equals(strings.get(i))) {
                strings.remove(i);
                break;
            }
        }


        boolean flag = true;
        while(flag){
            char charAt = word.charAt(word.length() - 1);
            ArrayList<String> list = map.get(charAt);
            if (list != null&&list.size()>0) {
                word+=list.get(0);
                list.remove(0);
            }else{
                flag = false;
            }
        }
        System.out.println(word);


    }
}
